#coding=utf-8

import socket
import urllib2
import traceback
from ripper.handler import socks



def _create_connection(address):
    msg = "getaddrinfo returns an empty list"
    host, port = address
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            sock = socket.socket(af, socktype, proto)
            sock.connect(address)
            return sock

        except socket.error, msg:
            if sock is not None:
                sock.close()

    raise socket.error, msg

if __name__ == '__main__':
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 7070)
    socket.socket = socks.socksocket
    #socket.create_connection = _create_connection
    re = urllib2.urlopen("http://www.sexinsex.net/")
    
    print re.read()